package com.cloudfun.campusshare.controller;

import com.cloudfun.campusshare.common.model.dto.VerifyCodeH5LoginDTO;
import com.cloudfun.campusshare.common.model.dto.VerifyCodeLoginDTO;
import com.cloudfun.campusshare.common.model.dto.WeChatLoginDTO;
import com.cloudfun.campusshare.common.model.vo.SessionVO;
import com.cloudfun.campusshare.common.response.BaseResult;
import com.cloudfun.campusshare.service.SessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @Author : linyangping
 * @Date : Created in 5:06 PM 2019/11/19
 */
@Validated
@RestController
@RequestMapping("/v1/session")
@Api(value = "会话模块", description = "会话模块", position = 9)
public class SessionController {

    @Autowired
    private SessionService sessionService;

    @ApiOperation(value = "登陆", notes = "登陆")
    @RequestMapping(value = "", method = RequestMethod.POST)
    BaseResult<?> login(@ApiParam(value = "SessionVo", required = true) @Valid @RequestBody SessionVO sessionVO,
                        HttpServletRequest request, HttpServletResponse response) {
        return sessionService.loginWithPassword(sessionVO, request, response);
    }

    @ApiOperation(value = "带验证码登陆", notes = "带验证码登陆")
    @RequestMapping(value = "/captcha", method = RequestMethod.POST)
    BaseResult<?> loginByPasswordWithVerifyCode(@ApiParam(value = "createDTO", required = true)
                                                @Validated({SessionVO.Captcha.class}) @RequestBody SessionVO sessionVO,
                                                HttpServletRequest request, HttpServletResponse response) {
        return sessionService.loginWithPassword(sessionVO, request, response);
    }

    @ApiOperation(value = "微信快捷登录", notes = "微信快捷登录")
    @RequestMapping(value = "/wechat", method = RequestMethod.POST)
    BaseResult<?> loginByWeChat(@ApiParam(value = "loginDTO", required = true) @Valid @RequestBody WeChatLoginDTO loginDTO,
                                HttpServletRequest request, HttpServletResponse response) {
        return sessionService.loginByWeChat(loginDTO, request, response);
    }

    @ApiOperation(value = "验证码登录", notes = "验证码登录")
    @RequestMapping(value = "/verifyCode", method = RequestMethod.POST)
    BaseResult<?> loginByVerifyCode(@ApiParam(value = "loginDTO", required = true) @Valid @RequestBody VerifyCodeLoginDTO loginDTO,
                                    HttpServletRequest request, HttpServletResponse response) {
        return sessionService.loginByVerifyCode(loginDTO, request, response);
    }


    @ApiOperation(value = "H5手机验证码登录", notes = "H5手机验证码登录")
    @RequestMapping(value = "/verifyCode/h5", method = RequestMethod.POST)
    BaseResult<?> loginByVerifyCode4H5(@ApiParam(value = "verifyCodeH5LoginDTO", required = true) @Valid @RequestBody VerifyCodeH5LoginDTO verifyCodeH5LoginDTO,
                                       HttpServletRequest request, HttpServletResponse response) {
        return sessionService.loginByVerifyCode4H5(verifyCodeH5LoginDTO, request, response);
    }

}
